package com.maple.common.utils.agreements;
import com.maple.common.utils.Tools;
import java.math.BigDecimal;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class B10AgreementUtil {
    /**
     * 截取字符串
     * */
    public static void testRegexp(String s,CallBackWeight callBackWeight) {
        if (s != null && !"".equals(s)) {
//            String regex = "FF[0-9a-fA-F]{2}[0-9]{6}";
            String regex = "776E[0-9a-fA-F]{18}0D0A";

            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(s);
            while (matcher.find()) {
                String matcherString = matcher.group();
                System.out.println(matcherString);
                byte[]data=Tools.parseHexStr2Byte(matcherString);
                StringBuilder builder=new StringBuilder();
                for (int i = 2; i < data.length-4; i++) {
                    builder.append((char) data[i]);
                }
                String res=builder.toString();
                System.out.println(res);
                try {
//                    String w=res.substring(0,res.length()-2);
                    BigDecimal decimal=new BigDecimal(res.trim());
                    System.out.println(decimal.toString());
                    callBackWeight.succeed(decimal.toString());
                }catch (Exception e){
                    System.out.println("解析错误");
                }

            }
        }
    }

}
